from pyspark import SparkContext, SparkConf

conf = SparkConf().setAppName("map").setMaster("local")
sc = SparkContext(conf=conf)


rdd = sc.parallelize(["hello world", "goodbye world", "hi world"])
rdd = rdd.flatMap(lambda x: x.split())
print(rdd.collect())  # ['hello', 'world', 'goodbye', 'world', 'hi', 'world']